#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPushButton"
#include "cyuan.h"
#include <QVBoxLayout>
#include "chui.h"
#include "QDebug"
#include "plan.h"
#include "QFileDialog"

int cyuan_count = 0;
int chui_count = 0;
int plan_count = 0;
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    // 创建添加碳源按钮
    QWidget *scrollWidget = new QWidget(this);
    ui->scrollArea_cyuan->setWidget(scrollWidget);
    layout = new QVBoxLayout(scrollWidget);
    scrollWidget->setLayout(layout);
    connect(ui->addButton_cyuan, &QPushButton::clicked,this , &MainWindow::add_yuan);


    //创建添加碳汇按钮
    QWidget *scrollWidget2 = new QWidget(this);
    ui->scrollArea_chui->setWidget(scrollWidget2);
    layout2 = new QVBoxLayout(scrollWidget2);
    scrollWidget2->setLayout(layout2);
    connect(ui->addButton_chui, &QPushButton::clicked,this , &MainWindow::add_hui);

    //获取左下输入信息的值并给出方案价格
    //创建方案
    QWidget *scrollWidget3 = new QWidget(this);
    ui->scrollArea_plan->setWidget(scrollWidget3);
    layout3 = new QVBoxLayout(scrollWidget3);
    scrollWidget3->setLayout(layout3);
    //获取信息
    connect(ui->calButton, &QPushButton::clicked,this , &MainWindow::cal);


    //打开文件按钮
    connect(ui->importButton,&QPushButton::clicked,this,[=](){
        //打开文件对话框
        QString path = QFileDialog::getOpenFileName(this,"打开文件");
    });


    //保存数据  输入框的数据点击保存后不能修改
    connect(ui->saveButton,&QPushButton::clicked,this,[=](){
        //输入框的数据不能修改
        ui->lineEdit->setReadOnly(true);;
        ui->lineEdit_2->setReadOnly(true);;
        ui->lineEdit_3->setReadOnly(true);;
        ui->lineEdit_4->setReadOnly(true);;
        ui->lineEdit_5->setReadOnly(true);;
        ui->lineEdit_6->setReadOnly(true);;
        ui->lineEdit_7->setReadOnly(true);;
        ui->lineEdit_8->setReadOnly(true);;
        ui->lineEdit_9->setReadOnly(true);;
        ui->lineEdit_10->setReadOnly(true);;
    });


    //导出数据
    connect(ui->exportButton,&QPushButton::clicked,this,[=](){
        //保存文件对话框
        QString path = QFileDialog::getSaveFileName(this,"保存文件");
    });


}
// 添加碳源
void MainWindow::add_yuan()
{
    cyuan_count++;
    // 创建并添加新的QWidget
    cyuan *cy = new cyuan(this);
    cy->setindex(cyuan_count);
    layout->addWidget(cy);

}
// 添加碳汇
void MainWindow::add_hui()
{
    chui_count++;
    // 创建并添加新的QWidget
    chui *ch = new chui(this);
    ch->setindex(chui_count);
    layout2->addWidget(ch);

}

//计算
void MainWindow::cal(){
    QString info1 = ui->lineEdit->text();
    QString info2 = ui->lineEdit_2->text();
    QString info3 = ui->lineEdit_3->text();
    QString info4 = ui->lineEdit_4->text();
    QString info5 = ui->lineEdit_5->text();
    QString info6 = ui->lineEdit_6->text();
    QString info7 = ui->lineEdit_7->text();
    QString info8 = ui->lineEdit_8->text();
    QString info9 = ui->lineEdit_9->text();
    QString info10 = ui->lineEdit_10->text();
    plan_count++;
    plan *pl = new plan(this);
    //计算
    pl->setdata(plan_count,info1,info2,info3,info4,info5,info6,info7,info8,info9,info10);
    layout3->addWidget(pl);


}
MainWindow::~MainWindow()
{
    delete ui;
}

